;
const food_cat_set_ops = {
    init () {
        this.eventBind();
    },
    eventBind () {
        $(".wrap_cat_set .save").click(function() {
            let btn_target = $(this);
            if (btn_target.hasClass('disabled')) {
                common_ops.alert("正在处理提交中")
                return;
            }
            const name_target = $(".wrap_cat_set input[name=name]");
            const name = name_target.val();

            const weight_target = $(".wrap_cat_set input[name=weight]");
            const weight = weight_target.val();

            if (!name || name.length < 2) {
                common_ops.tip("请输入符合规范的分类名称！！", name_target)
                return false;
            }
           if (!weight) {
                common_ops.tip("请输入符合规范的权重！！", weight_target)
                return false;
           }

            btn_target.addClass("disabled")
            const data = {
                name,
                weight,
                id: $(".wrap_cat_set input[name=id]").val()
            }
            $.ajax({
                url: common_ops.buildUrl("/food/cat-set"),
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    btn_target.removeClass("disabled");
                    let callback = null;
                    if (res.code === 200) {
                        callback = function () {
                            window.location.href = common_ops.buildUrl("/food/index")
                        }
                    }
                    common_ops.alert(res.msg, callback);
                }
            })
        })
    }
}

$(document).ready(function () {
    food_cat_set_ops.init()
})